import axios from "axios"
import {useStore} from "@/stores/counter";
import {Message} from "@arco-design/web-vue";

export const useAxios = axios.create({
    baseURL: "/api"
})

export interface BaseRsp<T> {
    code: number
    data: T
    msg: string
}

export interface ListData<T> {
    count: number
    list: T[]
}

export interface PageParamsType {
    page?: number
    limit?: number
    key?: string
    sort?: string
}

export interface DelParamsType {
    id_list: number[]
}


useAxios.interceptors.request.use((config) => {
    const store = useStore()
    config.headers["token"] = store.userInfo.token
    return config
})

useAxios.interceptors.response.use(rsp => {
    if (rsp.status !== 200) {
        // 失败的
        console.log(rsp.status)
        Message.error(rsp.statusText)
        return Promise.reject(rsp.statusText)
    }
    return rsp.data
}, (err) => {
    console.log("服务错误", err)
    Message.error(err.message)
    return Promise.reject(err.message)
})

// export function defaultDelAxios() {
//
// }
